# s = "25525511135"
# s="0000"
# s = "1010@3"
s="19216811"
def dfs(s,curSplitTime,begin,end,path,res):
    print("curSplitTime:",curSplitTime," begin:",begin," path:",path)
    if curSplitTime==4 and begin==end:
        res.append(path[:len(path)-1])
        return None
    if begin<len(s) and s[begin]=='0':
        path+=s[begin]+"."
        dfs(s,curSplitTime+1,begin+1,end,path,res)
    if begin<len(s) and s[begin]>'0' and s[begin]<='9':
        #限制开始元素的范围
        #分割单个字符的情况
        dfs(s,curSplitTime+1,begin+1,end,path+s[begin]+".",res)
        #分割两个字符的情况
        dfs(s,curSplitTime+1,begin+2,end,path+s[begin:begin+2]+".",res)
        #分割三个字符的情况
        if int(s[begin:begin+3])>=100 and int(s[begin:begin+3])<=255:
            dfs(s,curSplitTime+1,begin+3,end,path+s[begin:begin+3]+".",res)
    return None
def restoreIpAddresses(s):
    sLen=len(s)
    if sLen<4 or sLen>12:
        return []
    for i in s:
        if i<'0' or i>'9':
            return []
    res=[]
    dfs(s,0,0,sLen,"",res)
    print("最后结果：",res)

restoreIpAddresses(s)
